<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>校园一卡通</title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui, user-scalable=no">
    <meta http-equiv="cleartype" content="o n">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/assets/store/bound/css/style.css">
    <link rel="stylesheet" href="/assets/store/bound/css/layer.css">
</head>
<body>
    <div class="wraper">
       
        <div class="header">

            <if condition="$go eq 1">
                <a href="/base/store/userIndex/store_id/{BEESCRM:$store_id}" class="iconfont icon-zuo back"></a>
            <elseif condition="$go eq 2"/>
                <a href="/base/UserCenter/index/account_id/{BEESCRM:$account_id}" class="iconfont icon-zuo back"></a>
            <else />
                <a href="javascript:history.go(-1)" class="iconfont icon-zuo back"></a>
            </if>

            <div class="title text-center font-16">绑定一卡通</div>
        </div>
        <div class="classify content margin-t12">
            <div class="content-list flex">
                <div class="user-hint">学生账号</div>
                <div class="input"> 
                    <input type="text" id="name1" placeholder="学号">
                </div>
            </div>
            <div class="content-list flex">
                <div class="user-hint">学号/工号</div>
                <div class="input">
                    <input type="text" id="name" placeholder="学号">
                </div>
            </div>
            <div class="content-list flex">
                <div class="user-hint">账户密码</div>
                <div class="input" >
                    <input type="password" id="pass" placeholder="密码">
                </div>
            </div>
            <input type="hidden" id="user_id" value="{BEESCRM:$user_id}">
            <input type="hidden" id="cart_id" value="{BEESCRM:$cart_id}">
            <input type="hidden" id="store_id" value="{BEESCRM:$store_id}">
            <input type="hidden" id="account_id" value="{BEESCRM:$account_id}">
            <input type="hidden" id="go" value="{BEESCRM:$go}">
            <input type="hidden" id="on" value="{BEESCRM:$on}">
            <!-- <input type="hidden" id="accountId" value="{BEESCRM:$accountId}"> -->
            <input type="hidden" id="campuscard_id" value="{BEESCRM:$campuscard_id}">
            <p><a href="#" class="btn text-center font-16" id="jiance">绑定</a></p>  
        </div>
    </div>
</body>
<script src="/assets/store/bound/js/jquery-2.1.0.min.js"></script>
<script src="/assets/store/bound/js/layer.js"></script>
<script src="/assets/store/bound/js/public.js"></script> 
<script>
    // var height = $(window).height();
    // $('.wraper').css('minHeight', height);
    // 
    $('#jiance').on('click',function(){
            var campuscard_id = $('#campuscard_id').val();
            var user_id = $('#user_id').val();
            var name = $('#name').val();
            var name1 = $('#name1').val();
            var pass = $('#pass').val();
            var cart_id = $('#cart_id').val();
            var store_id = $('#store_id').val();
            var account_id = $('#account_id').val();
            var on = $('#on').val();
            var go = $('#go').val();

            var res = check_name(name);
            if(res !=1){
                $.alert('error',res);
                return false;
            }
             var res = check_name(name1);
            if(res !=1){
                $.alert('error',res);
                return false;
            }
            if(!pass){
             $.alert('error','密码不能为空');
             return false;
            }
         
            var data = {
                    'campuscard_id': campuscard_id,
                    'user_id': user_id,
                    'name': name,
                    'pass': pass,
                    'name1': name1
            };

            if(on != 1 && cart_id){
                 $.ajax({
                    url: "{BEESCRM::U('/base/store/add',array('store_id'=>$storeId))}",
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 'S') {
                            fm.alert(data.message);
                            setTimeout("location.href ='/index.php?g=base&m=store&a=confirmOrder&cart_id="+ cart_id +"&store_id="+store_id+"'", 2000);
                        } else {
                            fm.alert(data.message);
                            return false;
                        }
                    }
                });
                
            }else{
               $.ajax({
                    url: "{BEESCRM::U('/base/store/add',array('store_id'=>$storeId))}",
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 'S') {
                            fm.alert( data.message);
                            if(go == 2){
                                setTimeout("location.href ='/index.php?g=base&m=store&a=center&user_id="+ user_id +"&store_id="+store_id+"&go="+go+"&account_id="+account_id+"'", 2000);
                            }else{
                                setTimeout("location.href ='/index.php?g=base&m=store&a=center&user_id="+ user_id +"&store_id="+store_id+"&go="+go+"'", 2000);
                            }
                            
                        } else {
                            fm.alert(data.message);
                            return false;
                        }
                    }
                });
            }

    });

     function check_name(str){
        if(str==""||str==null){
            var info="请输入账号!";
            return info;
        }
        var pattern = /^[A-Za-z0-9]+$/;
        if(!(pattern.test(str))){
            var info='输入账号有特殊字符!';
            return info;
        }
        return 1;
    }
</script>
